
/**
	拦截订单服务类的下单方法，用于api跟踪
	更新最后交易时间戳
*/

//@Proxy(bean=OrderService,method=TxLog)
class OrderLogProxy {


	//@Autowired
	txLogService;

	//@Autowired
	lifeCircleService;


	doProxy(beanDefine,bean){

		const {txLogService,lifeCircleService} = this;

		return {

			method(wrapBean,method,args){

				const annotation = wrapBean.getMethodAnnotation('TxLog')

				const preData = {title:annotation.param.title,bean:wrapBean.beanDefine.className,method,args}

				txLogService.appendJson(preData)
			
				return wrapBean.next().then(result => {

					//记录正确结果
					txLogService.appendJson({result})

					//更新最后交易时间
					lifeCircleService.updateLastOrderTime();


					return new Promise(r => r(result))
				}).catch(error => {

					//记录错误信息
					txLogService.appendJson({error})
					return new Promise((r,n) => n(error))

				})

			}

		}

	}

}

 module.exports = { OrderLogProxy } 